package com.ro.userservice.controller;

import com.ro.commonmodule.entity.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Value("${config.redisTimeout}")
    Long redisTimeout;

    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping(value = "/test")
    public String test() {
        return "this is a User-Service";
    }

    @GetMapping(value = "/login")
    public String login() {

        //验证用户名和密码

        //生成token
        String token = JwtUtil.getToken("123");
        //将token存入redis
        redisTemplate.opsForValue().set(token, token, redisTimeout, TimeUnit.SECONDS);
        //将token返回
        return token;
    }
}
